package collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo4 {
    public static void main(String[] args) {
        Collection c1=new ArrayList();
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("c1:"+c1);//集合c1[java,c++,.net]

        Collection c2=new ArrayList();
        c2.add("android");
        c2.add("ios");
        c2.add("java");
        System.out.println("c2:"+c2);//集合c2[android,ios,java]

        c1.addAll(c2);//集合c1和集合c2合并
        System.out.println("c1:"+c1);//集合c1有改变[java,c++,.net,android,ios,java]
        System.out.println("c2:"+c2);//集合c2没有改变

        Collection c3=new ArrayList();
        c3.add("c++");
        c2.add("android");
        c3.add("php");
        System.out.println("c3:"+c3);//集合c3[c++,android,php]
        boolean contains=c1.contains(c3);
        System.out.println("是否包含:"+contains);

        //取交集：c1中仅保留与c3所共有的元素，而c3不变
       /* c1.retainAll(c3);
        System.out.println("c1:"+c1);//c1:[c++,android]
        System.out.println("c3:"+c3);//c3:[c++,android,php]*/

        //删交集：c1中删除与c3所共有的元素，而c3不变
        c1.retainAll(c3);
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);

    }
}
